$D$ - struktura danych reprezentująca tekst dla operacji $\text{Factorin}$
Prawie dobre reprezentacje:
Oznaczenia:
Algorytm:
def build_trie_schema(text):
trie = compute_initial_trie(text)
leaf = trie.leafs()[0]
for i in range(1, len(text)):
suffix = text[i:]
head = trie.find(suffix, leaf)
suffix_end = suffix[head.depth():]
leaf = head.graft(suffix_end)
return trie
tree = Tree()
# create first tree with root and one child
for i in range(1, len(text)):
a = text[i]
deepest # deepest leaf of tree
node = deepest.suffix_link
while((node != root) and (a not in node.children)):
child = node.add_child(a)
# add suffix links for the child
tree = Tree()
# create first tree with root and one child
node = tree.root
for i in range(1, len(text)):
a = text[i]
if(a in node.children):
node = node.children[a]
# it's possible that the child has to be created
else:
node = node.implicit_suffix_link()
while((node != root) and (a not in node.children)):
child = node.add_child(a)
# add suffix links for the child
node = node.children[a]
Rozmiar drzewa sufiksów jest rzędu $O(|T|)$
last_head = head = self.root
node = self.root
leaf = self.root.child(0)
text_length = len(text)
for i in range(1, text_length):
suffix = text[i:]
leaf_label = leaf.label()
head_label = head.label()
node = head.parent.link
node = node.fast_find(head_label)
if(node.size() == 1):
head = node
else:
head = node.slow_find(leaf_label)
leaf = head.graft(?)
last_head.add_link(node)
last_head = head